<?php

namespace app\common\model;

use think\Model;

class LitestoreShoporder extends Model
{
    // 表名
    protected $name = 'litestore_shoporder';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    
//    // 追加属性
//    protected $append = [
//        'status_text',
//        'play_time_text',
//        'play_name_text'
//    ];

    //自定义初始化
    protected function initialize()
    {
        //需要调用`Model`的`initialize`方法
        parent::initialize();
        //TODO:自定义的初始化
    }

//    public function getOrderStatusAttr($value)
//    {
//        $status = [0=>'待付款',1=>'已付款'];
//        return $status[$value];
//    }

    public function getPlayTimeAttr($value)
    {
        return date('Y-m-d H:i:s',$value);
    }

    public function getPlayNameAttr($value)
    {
        $status = [1=>'支付宝',2=>'微信',3=>'银联',4=>'余额支付'];
        return $status[$value];
    }


    public function shop()
    {
        return $this->belongsTo('Litestoreshop', 'litestore_shop_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function shopcategory()
    {
        return $this->belongsTo('Litestoreshopcategory', 'litestore_shopcategory_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }




    public function getplayUsername($id){

        $palyuser=User::get(['id'=>$id]);
        return $palyuser['username'];
    }

    public function getplayUserid($name){

        $palyuser=User::get(['username'=>array('like','%'.$name.'%')]);
        return $palyuser['id'];
    }



}
